package com.cheyun.netsalev3.view.dm.detail

import android.util.Log
import android.view.LayoutInflater
import android.widget.LinearLayout
import androidx.databinding.DataBindingUtil
import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProviders
import com.cheyun.netsalev3.R
import com.cheyun.netsalev3.utils.BaseFragment
import com.cheyun.netsalev3.databinding.*
import com.cheyun.netsalev3.viewmodel.DmClueDetailsActivityViewModel


class DmDetailsFragment : BaseFragment<FragmentDmDetailsBinding>() {
    override fun initContentView(): Int {
        return R.layout.fragment_dm_details
    }

    override fun initViewModel(): ViewModel? {
        activity?.apply {
            return ViewModelProviders.of(this).get(DmClueDetailsActivityViewModel::class.java)
        }
        return null
    }

    override fun initView() {

    }

    override fun initData() {
        binding.viewModel?.bottomList?.observe(this, Observer { list ->
            binding.linearLayout.removeAllViews()
            for (i in list) {
                var itembinding =
                        DataBindingUtil.inflate<FragmentDmDetailItemBinding>(LayoutInflater.from(context),
                                R.layout.fragment_dm_detail_item, null, false)
                var param = LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.WRAP_CONTENT, 1f)
                itembinding.root.layoutParams = param
                itembinding.item = i
                itembinding.viewModel = binding.viewModel
                binding.linearLayout.addView(itembinding.root)
            }
        })
        binding.viewModel?.specName?.observe(this, Observer { it->binding.txtSpec.text = it })
        binding.viewModel?.time?.observe(this, Observer { it->binding.txtTime.text = it })
    }

    override fun lazyInit() {
        Log.i(TAG,"override lazyinit")
    }
}
